package com.gxa.meiye.sso.service.impl;

import com.gxa.meiye.sso.entity.Consumer;
import com.gxa.meiye.sso.repository.UserRepository;
import com.gxa.meiye.sso.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author: zy
 * @CreateTime: 2022-07-25  15:20
 */
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Autowired
    private UserRepository userRepository;
    @Override
    public boolean del(String phone) {
        Consumer allByPhoneEquals = userRepository.findAllByPhoneEquals(phone);
        String key= ConsumerServiceImpl.SALT+allByPhoneEquals.getToken();;
        if (redisTemplate.hasKey(key)){
            Boolean delete = redisTemplate.delete(key);
            if (delete) {
                return true;
            }
            return false;
        }
        return true;
    }
}
